/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.cheque;

import br.edu.cliente.Cliente;
import br.edu.util.GenericDAO;
import br.edu.util.HibernateUtil;
import java.util.List;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author 'Pedro
 */
public class ChequeDAO extends GenericDAO<Cheque>{
    
    public ChequeDAO(){
        super(Cheque.class);
    }

    public boolean salvar(Cheque cheque) {
        if(cheque.getId()==0){
            adicionar(cheque);
        } else {
            atualizar(cheque);
        }
        return true;
    }

    public List<Cheque> pesquisarNrChequeLike(String text) {
        List<Cheque> cheques=null;
        setSessao(HibernateUtil.getSessionFactory().openSession());
        setTransacao(getSessao().beginTransaction());
        cheques = (List<Cheque>) getSessao().createCriteria(Cheque.class).add(Restrictions.ilike("nrcheque", text)).list();
        getSessao().close();
        return cheques;
    }

    public Cheque pesquisarCodigo(Integer valueOf) {
        Cheque cheque;
        setSessao(HibernateUtil.getSessionFactory().openSession());
        setTransacao(getSessao().beginTransaction());
        cheque = (Cheque) getSessao().createCriteria(Cheque.class).add(Restrictions.eq("id", valueOf)).uniqueResult();
        getSessao().close();
        return cheque;
    }
}
